package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.InvoiceDao;
import cn.itcast.domain.cargo.Invoice;
import cn.itcast.domain.cargo.InvoiceExample;
import cn.itcast.service.cargo.InvoiceService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.UUID;

@Service(timeout = 1000000)
public class InvoiceServiceImpl implements InvoiceService {
    @Autowired
    private InvoiceDao invoiceDao;

    @Override
    public PageInfo<Invoice> findByPage(InvoiceExample invoiceExample, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Invoice> list = invoiceDao.selectByExample(invoiceExample);
        return new PageInfo<>(list);
    }

    @Override
    public void deleteByPrimaryKey(String invoiceId) {
        invoiceDao.deleteByPrimaryKey(invoiceId);
    }

    @Override
    public void insert(Invoice record) {
        invoiceDao.insert(record);
    }

    @Override
    public void insertSelective(Invoice record) {
        record.setInvoiceId(UUID.randomUUID().toString());
        record.setStatus(0);
        invoiceDao.insertSelective(record);
    }

    @Override
    public List<Invoice> selectByExample(InvoiceExample example) {
        return invoiceDao.selectByExample(example);
    }

    @Override
    public Invoice selectByPrimaryKey(String invoiceId) {
        return invoiceDao.selectByPrimaryKey(invoiceId);
    }

    @Override
    public void updateByPrimaryKeySelective(Invoice record) {
        invoiceDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public void updateByPrimaryKey(Invoice record) {
        invoiceDao.updateByPrimaryKey(record);
    }
}
